import tkinter as tk
from tkinter import colorchooser
from tkinter import messagebox


def choose_color():
    color_code = colorchooser.askcolor(title="选择颜色")

    if color_code[1]:
        root.config(bg=color_code[1])
        messagebox.showinfo("选中的颜色", f"您选择的颜色是: {color_code[1]}")


root = tk.Tk()
root.title("颜色选择示例")
root.geometry("300x200")

btn = tk.Button(root, text="选择颜色", command=choose_color)
btn.pack(pady=50)

root.mainloop()